package com.moliku.insurance.process.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * MybatisPlus 自动填充
 *
 * @author Mr.Liu
 * @since 2020-03-04
 */
@Slf4j
@Component
@ConditionalOnMissingBean(MybatisMetaObjectHandler.class)
public class MybatisMetaObjectHandler implements MetaObjectHandler {
    @Primary
    @Override
    public void insertFill(MetaObject metaObject) {
      /*  LoginSysUser sysUser = (LoginSysUser) SecurityUtils.getSubject().getPrincipal();
        log.info("插入信息填充：{}", sysUser);
        String username = sysUser == null ? "" : sysUser.getUsername();
        this.setFieldValByName("creator", username, metaObject);*/
        this.setFieldValByName("creationTime", LocalDateTime.now(), metaObject);
    }
    @Primary
    @Override
    public void updateFill(MetaObject metaObject) {
      /*  LoginSysUser sysUser = (LoginSysUser) SecurityUtils.getSubject().getPrincipal();
        log.info("修改信息填充：{}", sysUser);
        String username = sysUser == null ? "" : sysUser.getUsername();
        this.setFieldValByName("editor", username, metaObject);      */
        this.setFieldValByName("editTime", LocalDateTime.now(), metaObject);

    }
}